<template>
  <div>
    <van-popup
      class="assist-popup task-handle-popup"
      v-bind="$attrs"
      position="right"
      :style="{ width: '100%', height: '100%' }"
      v-on="$listeners"
      get-container="body"
    >
      <van-nav-bar
        class="gm-nav-bar"
        left-text="维修协助"
        left-arrow
        @click-left="$emit('input', false)"
      />
      <div class="handle-cont">
        <van-cell-group>
          <van-field :value="activeData.Number" label="报修编号" readonly />
          <van-field
            :value="activeData.OrderDescription"
            label="报修设备"
            type="textarea"
            rows="1"
            autosize
            placeholder="未知"
            readonly
          />
          <van-field
            :value="activeData.FailureType"
            label="故障类型"
            type="textarea"
            rows="1"
            autosize
            placeholder="未知"
            readonly
          />
          <van-field
            :value="selection.DisplayName"
            label="协助人员"
            placeholder="请选择"
            is-link
            clickable
            readonly
            @click="selectionPopupShow = true"
          />
        </van-cell-group>
      </div>
      <van-row class="handle-footer" gutter="20">
        <van-col span="12">
          <van-button type="default" block @click="handleCancel">
            取消
          </van-button>
        </van-col>
        <van-col span="12">
          <van-button type="info" block @click="handleConfirm">
            确定
          </van-button>
        </van-col>
      </van-row>
    </van-popup>
    <assist-selection-popup
      v-model="selectionPopupShow"
      :active-data="activeData"
      @confirm="changeSelection"
    />
  </div>
</template>

<script>
import { Pad_Repair_AssistanceTask } from "../../api/index";

export default {
  name: "AssistPopup",
  inheritAttrs: false,
  props: {
    activeData: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  components: {
    "assist-selection-popup": () => import("./AssistSelectionPopup.vue"),
  },
  data() {
    return {
      selection: {},
      selectionPopupShow: false,
    };
  },
  methods: {
    handleCancel() {
      this.$emit("input", false);
    },
    handleConfirm() {
      const params = {
        RepairId: this.activeData.Id,
        AssistanceUser: this.selection.Account,
      };
      Pad_Repair_AssistanceTask(params)
        .then((res) => {
          if (res.ReturnResult === "1") {
            this.$dialog
              .alert({
                message: res.Message,
                className: "success",
              })
              .then(() => {
                this.$emit("confirm");
                this.$emit("input", false);
              });
          } else {
            this.$notify(res.Message);
          }
        })
        .catch((err) => {
          this.$notify(err);
        });
    },
    changeSelection(data) {
      this.selection = data;
      this.selectionPopupShow = false;
    },
  },
};
</script>
